package com.idp.app.controller;

import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.idp.common.base.BaseController;
import com.idp.common.model.PageModel;
import com.idp.common.model.ResultModel;
import com.idp.app.dto.SyLxrDto;
import com.idp.app.dto.SyLxrSearchDto;
import com.idp.app.service.SyLxrService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 镇街检察联络表Controller
 * @author Simon
 */
@Api(tags="镇街检察联络表")
@RestController
@RequestMapping("/syLxr/")
public class SyLxrController extends BaseController {

	@Autowired
	private SyLxrService syLxrService;

	/**
	 * 分页查询
	 * @param syLxrSearchDto
	 * @return
	 */
	@ApiOperation(value="分页查询")
	@ApiImplicitParams({
		@ApiImplicitParam(name = "page", value = "页数", paramType = "query", required = true, defaultValue = "1"),
		@ApiImplicitParam(name = "rows", value = "每页行数", paramType = "query", required = true, defaultValue = "10")
	})
	@PostMapping("findByPage")
	public ResultModel<PageModel<SyLxrDto>> findByPage(@RequestBody SyLxrSearchDto syLxrSearchDto) {
		return ResultModel.success(syLxrService.findByPage(syLxrSearchDto));
	}

	/**
	 * 通过id查询
	 * @param syLxrDto
	 * @return
	 */
	@ApiOperation(value="通过id查询")
	@ApiOperationSupport(includeParameters = {"syLxrDto.id"})
	@PostMapping("getById")
	public ResultModel<SyLxrDto> getById(@RequestBody SyLxrDto syLxrDto) {
		return ResultModel.success(syLxrService.getById(syLxrDto.getId()));
	}

	/**
	 * 新增
	 * @param syLxrDto
	 * @return
	 */
	@ApiOperation(value="注意：新增-新增时将bz赋值地区编码")
	@ApiOperationSupport(ignoreParameters = {"syLxrDto.id"})
	@PostMapping("add")
	public ResultModel add(@RequestBody SyLxrDto syLxrDto) {
		syLxrService.add(syLxrDto);
		return ResultModel.success("新增成功", null);
	}

	/**
	 * 修改
	 * @param syLxrDto
	 * @return
	 */
	@ApiOperation(value="修改")
	@PostMapping("update")
	public ResultModel update(@RequestBody SyLxrDto syLxrDto) {
		syLxrService.update(syLxrDto);
		return ResultModel.success("修改成功", null);
	}

	/**
	 * 删除
	 * @param syLxrDto
	 * @return
	 */
	@ApiOperation(value="删除")
	@ApiOperationSupport(includeParameters = {"syLxrDto.id"})
	@PostMapping("delete")
	public ResultModel delete(@RequestBody SyLxrDto syLxrDto) {
		syLxrService.delete(syLxrDto.getId());
		return ResultModel.success("删除成功", null);
	}

}
